<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/12/26
  Time: 15:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--使用taglib指令导入核心标签库--%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>用户列表</title>
  <%--导入boostrap的css/jquery的js/boostrap的js--%>
  <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet" />
  <%--导入jquery的js--%>
  <script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
  <%--导入boostrap的js文件--%>
  <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</head>
<body>
<div class="table-responsive">
  <table class="table table-bordered table-hover table-striped table-condensed">
    <tr>
      <th>用户昵称</th>
      <th>用户密码</th>
      <th>真实姓名</th>
      <th>用户邮箱</th>
      <th>用户电话</th>
      <th>用户性别</th>
      <th>操作</th>
    </tr>
    <%--<c:forEach items="${list}" var="u"> --%> <%--u代表每一个user实体--%>
    <c:forEach items="${pb.list}" var="u">
      <tr align="center">
          <%--访问user实体里面的bean属性--%>
        <td>${u.username}</td>
        <td>${u.password}</td>
        <td>${u.name}</td>
        <td>${u.email}</td>
        <td>${u.telephone}</td>
        <td>${u.sex}</td>
        <td>
          <a class="btn btn-warning" href="${pageContext.request.contextPath}/admin?methodName=adminFindUser&uid=${u.uid}">修改</a>
            <%--超链接失效

                点击事件--%>
          <a   class="btn btn-danger" href="javascript:void(0)" onclick="deleteUser('${u.uid}')">删除</a>
        </td>
      </tr>
    </c:forEach>

  </table>
</div>
  <%--<table style="border-collapse: collapse;" align="center" width="950px" height="500px" border="1px">--%>
<div style="float: right">
  总页数  <b>${pb.totalPage} </b>  页 &ensp;&ensp;  共有<b>${pb.totalCount}</b>  条记录
</div>


<%--boostrap提供的分页组件--%>
<div style="margin-left: 300px">
  <nav aria-label="Page navigation">
    <ul class="pagination">
<%--      上一页--%>
      <%-- 判断当前页是否为第一页 --%>
  <c:if test="${pb.currentPage==1}">
    <%--禁用状态--%>
    <li class="disabled">
      <a href="javascript:void(0)" aria-label="Previous">
        <span aria-hidden="true">&laquo;</span>
      </a>
    </li>
  </c:if>
  <%--当前页不是第一页--%>
  <c:if test="${pb.currentPage!=1}">
    <li>
      <a href="${pageContext.request.contextPath}/admin?methodName=adminFindUserPage&currentPage=${pb.currentPage-1}&pageSize=3" aria-label="Previous">
        <span aria-hidden="true">&laquo;</span>
      </a>
    </li>
  </c:if>


  <%--每一个页码数--%>
  <%--
    c:foreach:
          begin：起始的索引值
          end:取出总页数
  --%>
  <c:forEach  begin="1" end="${pb.totalPage}" var="n" >
    <%--boostrap的class="active" 激活状态--%>
     <li class="active">
       <%--
          判断是否当前页
       --%>

       <c:if test="${pb.currentPage==n}">
          <a class="active" href="javascript:void(0)">${n}</a>
       </c:if>
     </li>
    <li>
        <%--如果不是当前页,分页查询--%>
      <c:if test="${pb.currentPage!=n}">
        <a href="${pageContext.request.contextPath}/admin?methodName=adminFindUserPage&currentPage=${n}&pageSize=3">${n}</a>
      </c:if>
    </li>



  </c:forEach>

      <%--<li><a href="#">2</a></li>
      <li><a href="#">3</a></li>
      <li><a href="#">4</a></li>
      <li><a href="#">5</a></li>--%>

  <%--下一页--%>
      <%--判断是否为最后一页--%>
    <c:if test="${pb.currentPage==pb.totalPage}">
      <li class="disabled">
        <a href="javascript:void(0)" aria-label="Next">
          <span aria-hidden="true">&raquo;</span>
        </a>
      </li>
    </c:if>

  <%--如果不是最后一页--%>
  <c:if test="${pb.currentPage!=pb.totalPage}">
    <li>
      <a href="${pageContext.request.contextPath}/admin?methodName=adminFindUserPage&currentPage=${pb.currentPage+1}&pageSize=3" aria-label="Next">
        <span aria-hidden="true">&raquo;</span>
      </a>
    </li>
  </c:if>


    </ul>
  </nav>
</div>

</body>
<script>
        function deleteUser(uid){
            //alert(uid) ;
          //友情提示
          //确认提示框
         var flag =  window.confirm("您忍心删除吗?") ;
         if(flag){
           //删除
           //当前窗口重新载入一个新的地址
           window.location.href="${pageContext.request.contextPath}/admin?methodName=adminDelUser&uid="+uid;
         }
        }

</script>
</html>
